<script setup lang="ts">
import { RouterView, useRoute } from 'vue-router'
import { Layout, Menu } from 'ant-design-vue'
import { VideoCameraOutlined, HistoryOutlined } from '@ant-design/icons-vue'
import { useRouter } from 'vue-router'
import { h, ref } from 'vue'

const router = useRouter()
const route = useRoute()
const collapsed = ref(false)

const menuItems = [
  {
    key: '/live',
    icon: () => h(VideoCameraOutlined),
    label: '实时监控',
  },
  {
    key: '/playback',
    icon: () => h(HistoryOutlined),
    label: '视频回放',
  },
]

const handleMenuClick = ({ key }: { key: string }) => {
  router.push(key)
}
</script>

<template>
  <a-layout class="app-layout">
    <a-layout-sider 
      v-model:collapsed="collapsed" 
      collapsible
      :width="240"
      :collapsed-width="80"
    >
      <div class="logo">
        摄像头监控系统
      </div>
      <a-menu
        theme="dark"
        mode="inline"
        :selected-keys="[$route.path]"
        :items="menuItems"
        @click="handleMenuClick"
      />
    </a-layout-sider>
    <a-layout class="main-layout">
      <a-layout-content class="content-area">
        <RouterView />
      </a-layout-content>
    </a-layout>
  </a-layout>
</template>

<style scoped>
.app-layout {
  min-height: 100vh;
  width: 100%;
}

.main-layout {
  min-height: 100vh;
}

.content-area {
  padding: 0;
  margin: 0;
  background: #f0f2f5;
  min-height: calc(100vh - 0px);
}

.logo {
  height: 32px;
  margin: 16px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: bold;
  font-size: 14px;
  transition: all 0.3s;
}

.logo.collapsed {
  font-size: 12px;
}

/* 确保布局不会出现滚动条问题 */
.ant-layout-sider {
  position: fixed !important;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 100;
}

.main-layout {
  margin-left: 240px;
  transition: margin-left 0.3s;
}

.main-layout.collapsed {
  margin-left: 80px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .main-layout {
    margin-left: 0;
  }
  
  .ant-layout-sider {
    position: relative !important;
  }
}
</style>
